* ----------------- GSS 2010 data 
use "${dir_raw}/GSS_panel06w123_R3.dta", clear

* --- data is collected at 2010 (wave3)
gen id = id_1
gen id3 = id_3

* ---------- time 
* year 
gen year = year_3 
recode dateintv_3 (missing=.), gen(dateintv)

gen str_dateintv = string(dateintv)
replace str_dateintv = "" if str_dateintv == "."

gen month = substr(str_dateintv,1,1)
gen day = substr(str_dateintv, 2,2) 

gen svydate = day+"/"+month+"/"+string(year)
gen svydate2 = date(svydate, "DMY")
format svydate2 %td

* day of week
gen day_of_week = dow(svydate2)
gen wkend = (day_of_week==0 | day_of_week == 6) if ~missing(day_of_week)
gen week_of_month = week(svydate2)

* ----------- subject's baseline characteristics  
gen r_age = age_3 if ~missing(age_3)
gen r_female = (sex_3==2) if ~missing(sex_3)
gen r_educ = educ_3 if ~missing(educ_3)
gen r_race = race_3 if ~missing(race_3)
	gen r_white = r_race==1 if ~missing(r_race)
	gen r_black = r_race==2 if ~missing(r_race)
	gen r_others = r_race==3 if ~missing(r_race)

gen r_marstat = marital_3
	gen r_married = marital_3==1 if ~missing(marital_3)
	gen r_single = marital_3 == 5 if ~missing(marital_3)

gen r_nchilds = childs_3 if ~missing(childs_3)
gen r_adults = adults_3 if ~missing(adults_3)

gen r_attendance = attend_3 if ~missing(attend_3)

gen r_wrkstat = wrkstat_3
	recode r_wrkstat (1 2 =1) (else=0), gen(r_working)
	recode r_wrkstat (3 4=1) (else=0), gen(r_unemployed)
	recode r_wrkstat (5=1) (else=0), gen(r_retired)
	recode r_wrkstat (6 7 8=1) (else=0), gen(r_otherworks)

gen r_partyid = partyid_3 if ~missing(partyid_3)
	gen r_partyid7 = partyid_3 +1 if partyid_3 < 7

gen r_ideology = polviews_3 if ~missing(polviews_3)

gen r_pol_interest0 = 4-polint1_2 
	replace r_pol_interest0  = r_pol_interest0 / 3

* ----------- network information 
gen n_size = numgiven_3 if ~missing(numgiven_3)
gen isolated = (n_size==0) if ~missing(n_size)
gen numgiven = numgiven_3


* relationship type 
forvalues i = 1/ 5{
	gen a`i'_spouse = 2 - spouse`i'_3
	gen a`i'_parent = 2 - parent`i'_3
	gen a`i'_sibling = 2 - sibling`i'_3
	gen a`i'_child = 2 - child`i'_3
	gen a`i'_othfam = 2 - othfam`i'_3
	gen a`i'_cowork =  2 - cowork`i'_3 
	gen a`i'_member =  2 - memgrp`i'_3 
	gen a`i'_neighbor =  2 - neighbr`i'_3 
	gen a`i'_friend =  2 - friend`i'_3 
	gen a`i'_advisor = 2 - advisor`i'_3 
	gen a`i'_other = 2 - other`i'_3
}

* ----------- interviewer related questions
gen intid = intid_3
gen nintid = intid 

sort year intid svydate2 id 
bysort year intid: gen casenum=_n
bysort year intid: egen case_N = count(n_size)
bysort year intid: egen case_n = rank(svydate2), track 
replace case_n = case_n - 1 

gen i_phonemode = mode_3==2 if ~missing(mode_3)
gen i_length = lngthinv_3 

gen i_fee = feelevel_3
replace i_fee = 0 if feeused_3 == 3 

gen i_female = intsex_3 == 2 if ~missing(intsex_3)
gen i_age = intage_3 

recode intethn_3 (1=1) (2=2) (3/5=3), gen(i_race)
	gen i_black = i_race == 2 if ~missing(i_race)
	gen i_white = i_race == 1 if ~missing(i_race)
	gen i_others = i_race == 3 if ~missing(i_race)
gen i_tenure = intyrs_3
gen i_uncoop = coop_3 
gen i_poorcomprend = comprend_3 

gen i_ballot = ballot

gen dataset = "GSS"
keep id id_3 dataset ballot vpsu vstrat sampcode  wtpan12 wtpan123 oversamp formwt r_* year month day svydate svydate2 dateintv /*
*/ n_size isolated a?_* /*
*/ intid  i_* 


saveold "${dir_processed}/gss_data2.dta", replace version(12)

